home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / XDME / Src / Menu / MenuControl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  4.9 KB  |  208 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     menucontrol.c
  5.  
  6.     DESCRIPTION
  7.     [X]DME intuition interface to menustrips.c
  8.  
  9.     NOTES
  10.  
  11.     BUGS
  12.     none known
  13.  
  14.     TODO
  15.     handling for MENU_HELP
  16.  
  17.     EXAMPLES
  18.  
  19.     SEE ALSO
  20.     mainloop
  21.  
  22.     INDEX
  23.  
  24.     HISTORY
  25.     18 Dec 1992 b_null created
  26.     11 Feb 1993 modifcations
  27.     $Date: 94/07/06 12:06:48 $ last update
  28.  
  29. ******************************************************************************/
  30.  
  31. /**************************************
  32.         Includes
  33. **************************************/
  34. #include "defs.h"
  35. #include "menubase.h"
  36.  
  37.  
  38. /**************************************
  39.         Globale Variable
  40. **************************************/
  41. Prototype APTR menu_cmd (struct IntuiMessage * im);
  42. /* Prototype void menu_cmd (struct IntuiMessage * im); */
  43.  
  44.  
  45. /**************************************
  46.       Interne Defines & Strukturen
  47. **************************************/
  48.  
  49. typedef struct INode {
  50.     struct MinNode node;
  51.  /* XITEM     * item; */
  52.     int        len;
  53.     char       com[0];  /* that means : the rest of that node contains a string */
  54. } IINODE;
  55.  
  56.  
  57. /**************************************
  58.         Interne Variable
  59. **************************************/
  60.  
  61.  
  62. /**************************************
  63.        Interne Prototypes
  64. **************************************/
  65.  
  66.  
  67. #ifndef NOT_DEF
  68.  
  69. /*****************************************************************************
  70.  
  71.     NAME
  72.     menu_cmd
  73.  
  74.     PARAMETER
  75.     struct IntuiMessage * im
  76.  
  77.     RESULT
  78.     -/-
  79.  
  80.     RETURN
  81.     void
  82.  
  83.     DESCRIPTION
  84.     work on all menuselections done;
  85.     first set them all into a new queue, that does not
  86.     change if we modify currentmenu, then pass 'em to the
  87.     parser (or better a duplicate of them)
  88.  
  89.     NOTES
  90.     that method disables use of MENU_HELP
  91.     we should be able to do almost everything to our menus, also during
  92.     work on multiselections!
  93.  
  94.     THAT FUNCTION SHOULD BE RE-ENTRANT
  95.  
  96.     BUGS
  97.     what, if we close our window during that operation ????
  98.  
  99.     WARN: that function was neither compiled nor tested up to now
  100.           (we still use the function at the end of this file)
  101.  
  102.     EXAMPLES
  103.  
  104.     SEE ALSO
  105.     main/main
  106.  
  107.     INTERNALS
  108.     our method is horrible - it takes lots of resources,
  109.     but I think, this is the easiest way (else we had to lock our menustrip
  110.     and then queue up all operations to it)
  111.  
  112.     HISTORY
  113.     18 Dec 1992 b_null created
  114.     09 Feb 1993 b_null multiselection added
  115.     11 Feb 1993 b_null BUG FIX : all selections are done "buffered"
  116.  
  117. ******************************************************************************/
  118.  
  119. APTR /* void */ menu_cmd (struct IntuiMessage * im)
  120. {
  121.     MENUSTRIP * ms = currentmenu();
  122.     struct MinList buffs;
  123.  
  124.     NewList ((struct List *)&buffs);
  125.     if (im != NULL && im->Class == IDCMP_MENUPICK && ms != NULL) {
  126.     long           code = im->Code;
  127.     XITEM         * item;
  128.     IINODE         * in;
  129.  
  130.     while (item = (XITEM *)ItemAddress (ms->data, code)) {
  131.         if (item->com != NULL) {
  132.         int len = sizeof (IINODE) + strlen (item->com) + 1;
  133.  
  134.         if (in = AllocFunc (len, MEMF_ANY)) {
  135.             in->len = len;         /* we MUST remember the size here, as do_command might destroy the string-contents */
  136.             strcpy (in->com, item->com);
  137.          /* in->item = item; */
  138.             AddTail ((struct List *)&buffs, (struct Node *)in);
  139.         } /* if malloced */
  140.         } /* if command carrier */
  141.         code = item->item.NextSelect;
  142.     } /* while pending selections */
  143.  
  144.     while (in = (IINODE *)RemHead ((struct List *)&buffs)) {
  145.         do_command (in->com);
  146.         FreeFunc (in, in->len);
  147.     } /* while commands left in queue */
  148.  
  149. #ifdef NOT_DEF
  150.     /* that method has one serious bug: we can not be sure to hit the right items */
  151.     char buffer[LINE_LENGTH];
  152.     while (item = (XITEM *)ItemAddress (ms->data, code)) {
  153.         if (item->com) {
  154.         strcpy (buffer, item->com);
  155.         do_command (buffer);
  156.         clearbreaks ();
  157.         } /* if item->com */
  158.     } /* while item */
  159. #endif
  160.     } /* if im */
  161.  
  162.     return (NULL);
  163. } /* menu_cmd */
  164.  
  165. #else
  166.  
  167. /*****************************************************************************
  168.  
  169.     RESULT
  170.     address of a command that is referred by the
  171.     selected menu;
  172.  
  173.     RETURN
  174.     APTR
  175.  
  176.     DESCRIPTION
  177.     we simply check if the command was a correct
  178.     menu-selection and return some data that was
  179.     stored together with the Intuition-structure
  180.  
  181.     NOTES
  182.     we don not know, the structure of that data;
  183.     so user might have to call macroname, macrobody
  184.     or something like that before he is getting the wanted data
  185.  
  186.     INTERNALS
  187.     falls korrekter Menueaufruf
  188.         gib entsprechendes Macro zurueck
  189.     sonst gib NULL zurueck
  190.  
  191. ******************************************************************************/
  192.  
  193. APTR menu_cmd (struct IntuiMessage * im)
  194. {
  195.     XITEM *item;
  196.  
  197.     if (item = (XITEM *)ItemAddress (((MENUSTRIP *)currentmenu())->data, im->Code)) {
  198.     return (item->com);
  199.     } /* if found item */
  200.     return (NULL);
  201. } /* menu_cmd */
  202.  
  203. #endif
  204.  
  205. /******************************************************************************
  206. *****  ENDE menucontrol.c
  207. ******************************************************************************/
  208.